//
//  BLCommendLiveRoomCell.swift
//  BLLiveTelecast
//
//  Created by BigL055 on 16/5/30.
//  Copyright © 2016年 bigL.liveTelecast.com. All rights reserved.
//

import UIKit

class BLCommendLiveRoomCell: UITableViewCell {
    
    //标签按钮
    @IBOutlet weak var tagNameBtn: UIButton!
    //标签图片图层
    @IBOutlet weak var tagImageView: UIImageView!
    //房间Btn组
    @IBOutlet weak var roomBtn01: BLLiveRoomSingleButton!
    @IBOutlet weak var roomBtn02: BLLiveRoomSingleButton!
    @IBOutlet weak var roomBtn03: BLLiveRoomSingleButton!
    @IBOutlet weak var roomBtn04: BLLiveRoomSingleButton!
    
    //房间数组
    lazy var roomButtonArray = [BLLiveRoomSingleButton]()
    
    

    
    var liveRoomitem = BLLiveRoomItem(){
        didSet{
            setupUI()
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        roomButtonArray.append(roomBtn01)
        roomButtonArray.append(roomBtn02)
        roomButtonArray.append(roomBtn03)
        roomButtonArray.append(roomBtn04)
        //配置cell属性
        self.autoresizingMask = UIViewAutoresizing.None;
        self.selectionStyle = UITableViewCellSelectionStyle.None;
        
        
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}


extension BLCommendLiveRoomCell{
    func setupUI() {
        tagNameBtn.setTitle(liveRoomitem.tag_name, forState: .Normal)
        
        for i in 0..<liveRoomitem.roomlistArray.count {
            
            let roomItem = liveRoomitem.roomlistArray[i]
            let btn = roomButtonArray[i]
            btn.tag = i
            btn.setupRoomData(isPhneLive: false,
                              onlineNumber: roomItem.online,
                              userName: roomItem.nickname,
                              roomName: roomItem.room_name,
                              roomScrUrl: NSURL(string: roomItem.room_src!),
                              roomID: roomItem.room_id)
            btn.addTarget(self, action: #selector(roomBtnClick(_:)), forControlEvents: UIControlEvents.TouchUpInside)
            
            
        }
    }
}


extension BLCommendLiveRoomCell{
    
    @IBAction func getMoreButton(sender: UIButton) {
        print("BLCommendVerticalCell 更多按钮")
        print(liveRoomitem.tag_id)
        
        let tagID = liveRoomitem.tag_id
        if tagID != -1 {
            
            print("BLCommendLiveRoomCell + \(tagID)")
            //更多按钮 - 跳转通知

            
            let tagName : String = (tagNameBtn.titleLabel?.text)!
            
            
            NSNotificationCenter.defaultCenter().postNotificationName(kGetMoreNotification, object: tagID,userInfo: [kGetMoreNotificationID : tagName])

        }
        
    }
    
    func roomBtnClick(btn : BLLiveRoomSingleButton) {
        
        NSNotificationCenter.defaultCenter().postNotificationName(kPushLiveRoomNotification, object: btn.roomID)
        
       }
}




